using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerCounterAttackState : PlayerState
{

    public PlayerCounterAttackState(Player player, PlayerStateMachine playerStateMachine, string animBoolName) : base(player, playerStateMachine, animBoolName)
    {
    }

    public override void Enter()
    {
        base.Enter();
        player.animator.SetBool("successfulCounterAttack", false);
    }

    public override void Exit()
    {
        base.Exit();
    }

    public override void Update()
    {
        base.Update();
        player.SetZeroVelocity();
        Collider2D[] collider2dArray = Physics2D.OverlapCircleAll(player.attackCheck.position,player.attackRadius); 
        foreach(var hit in collider2dArray)
        {
            if (hit.GetComponent<Enemy>() != null)
            {
                if (hit.GetComponent<Enemy>().CanBeHit())
                {
                    stateTime = 1f;
                    player.animator.SetBool("successfulCounterAttack", true);
                    player.skill.parrySkill.CanUseSkill();
                    player.skill.parrySkill.MakeMirageOnParry(hit.transform);
                }
            }
        }
        if (stateTime < 0 || triggerCalled)
            playerStateMachine.ChangeState(player.playerIdleState);
    }
}
